//
//  BSOptionAndDeviceInfoViewController.m
//  SuoSiApp
//
//  Created by zhang on 16/4/11.
//  Copyright © 2016年 Ym. All rights reserved.
//
#import <CoreLocation/CoreLocation.h>

#import "BSOptionAndDeviceInfoViewController.h"
#import "FMDB.h"


@interface BSOptionAndDeviceInfoViewController ()<CLLocationManagerDelegate,UIGestureRecognizerDelegate>
//自定义View
@property (nonatomic, strong) BSOptionAndDeviceInfoView *opdeView;
@property (nonatomic, strong) UIView *deviceInfoView;
@property (nonatomic, strong) UIView  *NCview;
@property (nonatomic,strong) FMDatabase *db;

@end

@implementation BSOptionAndDeviceInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _NCview = [[UIView alloc]initWithFrame:self.view.bounds];
    _NCview.backgroundColor = BSBackViewColor;
    _NCview.alpha = 0.5;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(deleteSelf)];
    tap.delegate = self;
    [_NCview addGestureRecognizer:tap];
    
    self.view.backgroundColor = [UIColor colorWithRed:235/255.0 green:236/255.0 blue:237/255.0 alpha:1];
    
    self.opdeView = [[BSOptionAndDeviceInfoView alloc]initWithFrame:CGRectMake(0, 0, kScrenWidth, kScrenHeight - 0)];
    self.opdeView.scrollView.bounces = YES;
    self.opdeView.scrollView .contentSize = CGSizeMake(kScrenWidth, self.opdeView.deviceInfoLB.bottom);
    
    [self.opdeView.backBT addTarget:self action:@selector(backBT) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.opdeView.saveBT addTarget:self action:@selector(backBT) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.opdeView.deviceInfoBT addTarget:self action:@selector(deviceInfo) forControlEvents:(UIControlEventTouchUpInside)];
    [self.opdeView.offLineBT addTarget:self action:@selector(offLine) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    [self.view addSubview: self.opdeView];
    [self switchClict];
    
#pragma mark  创建数据库 保存对APP的设置
    [self creatAPPInformationSQList];
    
}

- (void)creatAPPInformationSQList{

    //  创建我们的数据库的路径 同时拼接数据库的文件名称
    NSString *nameList = [NSString stringWithFormat:@"APPSET.db"];
    
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:nameList];
    
    //  根据路径去创建一个数据库
    _db = [FMDatabase databaseWithPath:path];
    NSLog(@">> 地址%@",path);

//    添加键值对
    if ([_db open]) {
        NSLog(@"数据库打开成功");
    }else
    {
        NSLog(@"数据库打开失败");
    }
    
//    调用db的executeUpdata 这个方法的参数就是SQL 语句 logName为key
    

        [_db executeUpdate:@"CREATE TABLE APPInformationlist (isWifi text, isSignalWeak text, isElectricLow text, isDisconnected text, isFall text, isGPSON text, saveOfflineDate text)"];
    
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstCreat2"]) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstCreat2"];
        NSLog(@"交表");
//        NSString *SQLStr = [NSString stringWithFormat:@"INSERT INTO APPInformationlist (isGPSON) VALUES (?)"];

//      所有表格 置为NO
           [_db executeUpdate:@"INSERT INTO APPInformationlist (isWifi,isSignalWeak,isElectricLow,isDisconnected,isFall,isGPSON) VALUES (?,?,?,?,?,?)",@"YES",@"YES",@"YES",@"YES",@"YES",@"YES"];
        
//        [_db executeUpdate:@"INSERT INTO APPInformationlist (isSignalWeak) VALUES (?)",@"NO"];
//        [_db executeUpdate:@"INSERT INTO APPInformationlist (isElectricLow) VALUES (?)",@"NO"];
//        [_db executeUpdate:@"INSERT INTO APPInformationlist (isDisconnected) VALUES (?)",@"NO"];
//        [_db executeUpdate:@"INSERT INTO APPInformationlist (isFall) VALUES (?)",@"NO"];
//        [_db executeUpdate:@"INSERT INTO APPInformationlist (isGPSON) VALUES (?)",@"NO"];

    }
}
#pragma mark 获取对APP的设置
- (void)viewWillAppear:(BOOL)animated{
    
    
    
    NSArray *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString *path = @"/ECGData";
    
    NSString *filePath = [documents[0] stringByAppendingString:path];
    
    NSArray *listArrfile = [BSUserSGton getECGDataFileListFromPath:filePath];
    
    
// 取出设置的状态
    
    FMResultSet *rs = [_db executeQuery:@"SELECT * FROM APPInformationlist "];
    
    while ([rs next]) {
        NSString *isWifi = [rs stringForColumn:@"isWifi"];
        NSString *isSignalWeak = [rs stringForColumn:@"isSignalWeak"];
        NSString *isElectricLow = [rs stringForColumn:@"isElectricLow"];
        NSString *isDisconnected = [rs stringForColumn:@"isDisconnected"];
        NSString *isFall = [rs stringForColumn:@"isFall"];
        NSString *isGPSON = [rs stringForColumn:@"isGPSON"];

        for (int i = 1; i < 7; i++) {
            switch (i) {
                case 1:
                {
                    UISwitch *wifiSW = (UISwitch *)[self.opdeView viewWithTag:1];

                    if ([isWifi isEqualToString:@"NO"]) {
                        [wifiSW setOn:NO animated:YES];
                        
                        self.opdeView.wifiLB.text =[NSString stringWithFormat:@"WIFI(%ld)",listArrfile.count];
                        
                    } else {
                        [wifiSW setOn:YES animated:YES];
                        self.opdeView.wifiLB.text =[NSString stringWithFormat:@"所有网络(%ld)",listArrfile.count];
                    }
                
                }
                    break;
                case 2:
                {
                    UISwitch *sighnalSW = (UISwitch *)[self.opdeView viewWithTag:2];
                    
                    if ([isSignalWeak isEqualToString:@"NO"]) {
                        [sighnalSW setOn:NO animated:YES];
                    } else {
                        [sighnalSW setOn:YES animated:YES];
                        
                    }
                }
                    break;
                case 3:
                {
                    UISwitch *electSW = (UISwitch *)[self.opdeView viewWithTag:3];
                    
                    if ([isElectricLow isEqualToString:@"NO"]) {
                        [electSW setOn:NO animated:YES];
                    } else {
                        [electSW setOn:YES animated:YES];
                        
                    }
                }
                    break;
                case 4:
                {
                    UISwitch *disconnectSW = (UISwitch *)[self.opdeView viewWithTag:4];
                    
                    if ([isDisconnected isEqualToString:@"NO"]) {
                        [disconnectSW setOn:NO animated:YES];
                    } else {
                        [disconnectSW setOn:YES animated:YES];
                        
                    }
                }
                    break;
                case 5:
                {
                    UISwitch *fallSW = (UISwitch *)[self.opdeView viewWithTag:5];
                    
                    if ([isFall isEqualToString:@"NO"]) {
                        [fallSW setOn:NO animated:YES];
                    } else {
                        [fallSW setOn:YES animated:YES];
                        
                    }
                }
                    break;
                case 6:
                {
                    UISwitch *GPSSW = (UISwitch *)[self.opdeView viewWithTag:6];
                    
                    if ([isGPSON isEqualToString:@"NO"]) {
                        [GPSSW setOn:NO animated:YES];
                    } else {
                        [GPSSW setOn:YES animated:YES];
                        
                    }
                }
                    break;
                default:
                    break;
            }
        }
    }
    
}



//  找到几个switch 添加方法
- (void)switchClict{
// tag 值是1 ~ 6
    for (int i = 1; i < 7; i++) {
        switch (i) {
            case 1:
            {
                UISwitch *wifiSW = (UISwitch *)[self.opdeView viewWithTag:1];
                [wifiSW addTarget:self action:@selector(wifiSW:) forControlEvents:(UIControlEventTouchUpInside)];
            }
                break;
            case 2:
            {
                UISwitch *sighnalSW = (UISwitch *)[self.opdeView viewWithTag:2];
                [sighnalSW addTarget:self action:@selector(sighnalSW:) forControlEvents:(UIControlEventTouchUpInside)];
            }
                break;
            case 3:
            {
                UISwitch *electSW = (UISwitch *)[self.opdeView viewWithTag:3];
                [electSW addTarget:self action:@selector(electSW:) forControlEvents:(UIControlEventTouchUpInside)];
            }
                break;
            case 4:
            {
                UISwitch *disconnectSW = (UISwitch *)[self.opdeView viewWithTag:4];
                [disconnectSW addTarget:self action:@selector(disconnectSW:) forControlEvents:(UIControlEventTouchUpInside)];
            }
                break;
            case 5:
            {
                UISwitch *fallSW = (UISwitch *)[self.opdeView viewWithTag:5];
                [fallSW addTarget:self action:@selector(fallSW:) forControlEvents:(UIControlEventTouchUpInside)];
            }
                break;
            case 6:
            {
                UISwitch *GPSSW = (UISwitch *)[self.opdeView viewWithTag:6];
                [GPSSW addTarget:self action:@selector(GPSSW:) forControlEvents:(UIControlEventTouchUpInside)];
            }
                break;
                
                
            default:
                break;
        }
    }

    
}

// WiFi 或者所有网络
- (void)wifiSW:(UISwitch *)sw{
    
    NSString *path = [BSBluetoothSingleton shareBlutooth].filePath;
    
    NSArray *listArr = [BSUserSGton getECGDataFileListFromPath:path];
    NSLog(@"%@",listArr);
    
    

    if ( sw.isOn == NO) {
        
        //    管理文件
//        NSFileManager *filemanager = [NSFileManager defaultManager];
                            NSLog(@"开启WiFi上传");
        [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"AllNet"];

        self.opdeView.wifiLB.text = [NSString stringWithFormat:@"WIFI(%ld)",(unsigned long)listArr.count];
        
        [_db executeUpdate:@"update  APPInformationlist set isWifi = ?",@"NO"];
                        } else {
                            NSLog(@"所有网络均可上传");
                            [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"AllNet"];

                            
        self.opdeView.wifiLB.text = [NSString stringWithFormat:@"所有网络(%ld)",(unsigned long)listArr.count];
                            
                            [_db executeUpdate:@"update  APPInformationlist set isWifi = ?",@"YES"];
                        }
}
//信号弱提示音
- (void)sighnalSW:(UISwitch *)sw{
    if ( sw.isOn == YES) {
        NSLog(@"开启设备信号弱提示音");
        [_db executeUpdate:@"update  APPInformationlist set isSignalWeak = ?",@"YES"];

        [BSBluetoothSingleton shareBlutooth].isSignalWeak = YES;
        
    } else {
        NSLog(@"关闭设备信号弱提示音");
        [BSBluetoothSingleton shareBlutooth].isSignalWeak = NO;
        [_db executeUpdate:@"update  APPInformationlist set isSignalWeak = ?",@"NO"];

    }


}
//设备电量低提示音
- (void)electSW:(UISwitch *)sw{
    
    if ( sw.isOn == YES) {
        NSLog(@"开启设备电量低提示音");
        [BSBluetoothSingleton shareBlutooth].isSignalWeak = YES;
        [_db executeUpdate:@"update  APPInformationlist set isElectricLow = ?",@"YES"];


    } else {
        NSLog(@"关闭设备电量低提示音");
        [BSBluetoothSingleton shareBlutooth].isElectricLow = NO;
        [_db executeUpdate:@"update  APPInformationlist set isElectricLow = ?",@"NO"];

    }
    
    
}
//设备断开提示音
- (void)disconnectSW:(UISwitch *)sw{
    
    

    if ( sw.isOn == YES) {
        NSLog(@"开启设备设备断开提示音");
        [BSBluetoothSingleton shareBlutooth].isDisconnected = YES;
//        [_db executeUpdate:SQLStr,@"YES"];
        
        [_db executeUpdate:@"update  APPInformationlist set isDisconnected = ?",@"YES"];

    } else {
        NSLog(@"关闭设备断开提示音");
        [BSBluetoothSingleton shareBlutooth].isDisconnected = NO;
//        [_db executeUpdate:SQLStr,@"NO"];
        [_db executeUpdate:@"update   APPInformationlist set isDisconnected = ?",@"NO"];
    }
    
    
}
//设备脱落提示音
- (void)fallSW:(UISwitch *)sw{

    if ( sw.isOn == YES) {
        NSLog(@"开启设备设备脱落提示音");
        [BSBluetoothSingleton shareBlutooth].isFall = YES;
        [_db executeUpdate:@"update  APPInformationlist set isFall = ?",@"YES"];


    } else {
        NSLog(@"关闭设备设备脱落提示音");
        [BSBluetoothSingleton shareBlutooth].isFall = NO;
        [_db executeUpdate:@"update  APPInformationlist set isFall = ?",@"NO"];

    }
}
//GPS定位
- (void)GPSSW:(UISwitch *)sw{

//    开启表示 系统定位没有开 提醒设置
//    关闭表示 系统定位没有开 我也不管
    if ( sw.isOn == YES) {
        
//        if (([CLLocationManager locationServicesEnabled] == NO )) {
//            NSLog(@"开启GPS定位");
//            [BSBluetoothSingleton shareBlutooth].isGPSON = YES;
//            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否开启定位" preferredStyle:(UIAlertControllerStyleAlert)];
//            UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
//                ;
//            }];
//            UIAlertAction *setAcion = [UIAlertAction actionWithTitle:@"设置" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//                NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
//                //            @"prefs:root=LOCATION_SERVICES";mingyang.SuoSiApp
//                [[UIApplication sharedApplication] openURL:url];
//                
//            }];
//            [alert addAction:cancleAction];
//            [alert addAction:setAcion];
//            
//            [self presentViewController:alert animated:YES completion:^{
//                nil;
//            }];
//            
//            if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse){
//            }
//        }
        [_db executeUpdate:@"update  APPInformationlist set isGPSON = ?",@"YES"];
        [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"isRemindLocation"];


    } else {
//        NSLog(@"关闭GPS定位提醒");
//        [BSBluetoothSingleton shareBlutooth].isGPSON = NO;
         [_db executeUpdate:@"update  APPInformationlist set isGPSON = ?",@"NO"];

//      设置一个keyvalue 确定以后 要不要提醒定位
        [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"isRemindLocation"];

        
        
    }
}

#pragma mark 离线登陆方式
- (void)offLine{
     [self.view addSubview:_NCview];
    
    _deviceInfoView  = [[UIView alloc]initWithFrame:CGRectMake(kScrenWidth/8, kScrenHeight/2 - kMartin80, kScrenWidth*3/4 , 44 *6 - 1+ kMartin15)];
    _deviceInfoView.backgroundColor = BSBackColor;
    _deviceInfoView.layer.cornerRadius  = 8;
    CGFloat W = _deviceInfoView.width;
    
    UILabel *titleLable = [self getLableWithFrameY:0 FramX:8 width:W - 16 text:@"离线数据"];
    titleLable.textAlignment = NSTextAlignmentCenter;
    titleLable.backgroundColor = BSBackColor;
    [_deviceInfoView addSubview:titleLable];

    CGFloat Y = (43 + 1);
    UILabel *Lable3 =  [self getLableWithFrameY:Y FramX:0 width:W text:@"     3天"];
  

    [_deviceInfoView addSubview:Lable3];
    CGFloat YSwitch = kMartin5 + 43;
     UIButton *button3 =[self getButtonWithFrameY:YSwitch FrameH:0 name:nil];
    
    button3.tag = 530;
    
    Y += 44;
    UILabel *Lable5 =  [self getLableWithFrameY:Y FramX:0 width:W text:@"     7天"];
    [_deviceInfoView addSubview:Lable5];
    YSwitch += 44;
   UIButton *button5 = [self getButtonWithFrameY:YSwitch FrameH:0 name:nil];
    button5.tag = 531;
    
    
    Y += 44;
    UILabel *Lable7 =  [self getLableWithFrameY:Y FramX:0 width:W text:@"     15天"];
    [_deviceInfoView addSubview:Lable7];
    YSwitch += 44;
     UIButton *button7 =[self getButtonWithFrameY:YSwitch FrameH:0 name:nil];
    button7.tag = 532;

    Y += 44;
    UILabel *LableOff =  [self getLableWithFrameY:Y FramX:0 width:W text:@"     关闭"];

    [_deviceInfoView addSubview:LableOff];
    YSwitch += 44;
   UIButton *buttonOFF = [self getButtonWithFrameY:YSwitch FrameH:0 name:nil];
    buttonOFF.tag = 533;
//    保存的按钮
    Y += 44 + 3;
    UIButton *saveOfflineSetting = BSButton;
    saveOfflineSetting.frame = CGRectMake(kMartin20, Y + 7, _deviceInfoView.width - kMartin40, 43 - 6);
    saveOfflineSetting.backgroundColor = BSBTGreen;
    [saveOfflineSetting setTitle:@"保存" forState: (UIControlStateNormal)];

    saveOfflineSetting.layer.cornerRadius  =3;
    [saveOfflineSetting addTarget:self action:@selector(saveOfflineSet) forControlEvents:(UIControlEventTouchUpInside)];
    [_deviceInfoView addSubview:saveOfflineSetting];
    [self.view addSubview:_deviceInfoView];

#pragma mark 根据手机剩余的可用存储空间 决定离线数据存储时间
    
    [self confirmOfflineTime];
    

}

- (void)confirmOfflineTime{
    
    
    [[[NSUserDefaults standardUserDefaults]stringForKey:@"isRememberPassword"] isEqualToString:@"YES"];

    
    for (int i = 530; i < 534; i++) {
        UIButton *button = (UIButton *)[self.deviceInfoView viewWithTag:i];
        
        button.selected = NO;
    }

    
    CGFloat memoryValue = [BSUserSGton userHandle].memoryValue;
    if (memoryValue > 1000) {
        
        UIButton *button = (UIButton *)[self.deviceInfoView viewWithTag:532];
        [button setSelected:YES];
        
    }else if (memoryValue > 500){
        UIButton *button = (UIButton *)[self.deviceInfoView viewWithTag:531];
        [button setSelected:YES];
    
    }else if(memoryValue > 300){
        UIButton *button = (UIButton *)[self.deviceInfoView viewWithTag:530];
        [button setSelected:YES];
    
    }else{
        UIButton *button = (UIButton *)[self.deviceInfoView viewWithTag:533];
        [button setSelected:YES];
    }

}




- (void)saveOfflineSet{
    
//    确定 要保存几天的离线数据
    for (int i = 530; i < 534; i++) {
        UIButton *button = (UIButton *)[self.deviceInfoView viewWithTag:i];
        
        
        if (button.isSelected == YES) {
            switch (i) {
                case 530:
                    [[NSUserDefaults standardUserDefaults] setObject:@"3" forKey:@"saveOfflineTime"];

                    break;
                case 531:
                    [[NSUserDefaults standardUserDefaults] setObject:@"5" forKey:@"saveOfflineTime"];

                    break;
                case 532:
                    [[NSUserDefaults standardUserDefaults] setObject:@"7" forKey:@"saveOfflineTime"];

                    break;
                case 533:
                    [[NSUserDefaults standardUserDefaults] setObject:@"off" forKey:@"saveOfflineTime"];

                    break;
                    
                default:
                    break;
            }
            
            //      设置一个keyvalue 确定以后 要不要提醒定位
            [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"isRemindLocation"];
        }
        
    }
    
    

    [_NCview removeFromSuperview];
    [_deviceInfoView removeFromSuperview];

}


- (void)deviceInfo{
    

    
    [self.view addSubview:_NCview];
    
    _deviceInfoView  = [[UIView alloc]initWithFrame:CGRectMake(kScrenWidth/8, kScrenHeight/2 - kMartin80, kScrenWidth*3/4, 44 *4 - 1)];
    _deviceInfoView.backgroundColor = BSBackColor;
   _deviceInfoView.layer.cornerRadius  = 8;
    CGFloat W = _deviceInfoView.width;

    UILabel *titleLable = [self getLableWithFrameY:0 FramX:8 width:W - 16 text:@"设备信息"];
    titleLable.textAlignment = NSTextAlignmentCenter;
    titleLable.backgroundColor = BSBackColor;
    [_deviceInfoView addSubview:titleLable];
    CGFloat Y = (43 + 1);
    W = W*2/3;
    UILabel *VLable =  [self getLableWithFrameY:Y FramX:0 width:W text:@"   电压"];
    [_deviceInfoView addSubview:VLable];
    
    CGFloat VW = _deviceInfoView.width - W + 1;
    CGFloat X = VLable.right - 1;
    
    CGFloat bettryV = [BSBluetoothSingleton shareBlutooth].batVolValue;
    
    NSString *bettryVs = [NSString stringWithFormat:@"%.2fV",bettryV];
    
    
    UILabel *VlableV = [self getLableWithFrameY:Y FramX:X width:VW text:bettryVs];
    VlableV.textColor = BSGray;
    [_deviceInfoView addSubview:VlableV];

    Y += 44;
    UILabel *Slable = [self getLableWithFrameY:Y FramX:0 width:W text:@"   强度"];
    [_deviceInfoView addSubview:Slable];
    CGFloat RSSIV = [BSBluetoothSingleton shareBlutooth].RSSIValue;

    UILabel *SlableV = [self getLableWithFrameY:Y FramX:X width:VW text:[NSString stringWithFormat:@"%.2fdb",RSSIV]];
    SlableV.textColor = BSGray;

    [_deviceInfoView addSubview:SlableV];
    
    
    Y += 44;
    UILabel *Tlable = [self getLableWithFrameY:Y FramX:0 width:W text:@"   温度"];
    [_deviceInfoView addSubview:Tlable];
    CGFloat tempV = [BSBluetoothSingleton shareBlutooth].tempValue;

    UILabel *TlableV = [self getLableWithFrameY:Y FramX:X width:VW text:[NSString stringWithFormat:@"%.2f℃",tempV]];
    TlableV.textColor = BSGray;

    [_deviceInfoView addSubview:TlableV];
    
    
    [self.view addSubview:_deviceInfoView];
    
}
#pragma  tap
- (void)deleteSelf{

    

}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    NSString *str =  NSStringFromClass([touch.view class]);
    if ([str isEqualToString:@"UIView"]) {
        [_NCview removeFromSuperview];
        [_deviceInfoView removeFromSuperview];
    }
    
    
    return YES;
}
//返回上个界面
- (void)backBT{

    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (UIButton *)getButtonWithFrameY:(CGFloat)Y FrameH:(CGFloat)H name:(NSString *)name{

    UIButton *button = BSButton;
    button.frame = CGRectMake(_deviceInfoView.width - kMartin60, Y, 43 - 10, 43 - 10) ;
    button.layer.cornerRadius = 10;
    [button setBackgroundImage:[UIImage imageNamed:@"sz_btSelect_yes.png"] forState:(UIControlStateSelected)];
    [button setBackgroundImage:[UIImage imageNamed:@"sz_btSelect_no.png"] forState:(UIControlStateNormal)];
    button.selected = NO;
    [button addTarget:self action:@selector(selectOfflinLog:) forControlEvents:(UIControlEventTouchUpInside)];
    button.backgroundColor = BSGreen;
    [_deviceInfoView addSubview:button];
    return button;
}




- (void)selectOfflinLog:(UIButton *)sender{
    
//    取出所有的button tag值530 - 533
    NSLog(@"%ld",(long)sender.tag);
    for (int i = 530; i < 534; i++) {
        UIButton *button = (UIButton *)[self.deviceInfoView viewWithTag:i];
        
        button.selected = NO;
    }
    [sender setSelected:YES];
    
//    根据选择的按钮 觉得 存储时间
    

}

- (UILabel *)getLableWithFrameY:(CGFloat)Y FramX:(CGFloat)X width:(CGFloat)W text:(NSString *)text{
    
    CGRect frame = CGRectMake(X, Y, W , 43);
    UILabel *lable = [[UILabel alloc]initWithFrame:frame];
    lable.text = text;
    lable.textAlignment = NSTextAlignmentLeft;
    lable.font = [UIFont systemFontOfSize:20];
    lable.backgroundColor = BSWhite;
    return lable;
}
@end
